package openGl;

import android.app.ActivityManager;
import android.content.Context;
import android.content.pm.ConfigurationInfo;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;

import camera.view.RenderSurfaceView;
import openGl.camera.CameraSurfaceView;
import openGl.utils.ColorRender;

/**
 *@author:ike
 *@function: openGl实例程序
 *@creat time:14:42 2017/12/19
 **/

public class OpenGlDemoActivity  extends AppCompatActivity{

    private GLSurfaceView glSurfaceView;
    private CameraSurfaceView cameraSurfaceView;
    private RenderSurfaceView renderSurfaceView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        boolean b = checkSupportOpenGl();
        if (b){
//            glSurfaceView = new GLSurfaceView(this);
//            //设置openGl版本
//            glSurfaceView.setEGLContextClientVersion(2);
//            glSurfaceView.setRenderer(new ColorRender(this));
//            glSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
//            setContentView(glSurfaceView);
//            cameraSurfaceView=new CameraSurfaceView(this);
            renderSurfaceView=new RenderSurfaceView(this);
            setContentView(renderSurfaceView);
        }else {
            Toast.makeText(this, "设备不支持OpenGl2.0", Toast.LENGTH_SHORT).show();
        }
    }
    private boolean  checkSupportOpenGl(){
        ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
        ConfigurationInfo info = manager.getDeviceConfigurationInfo();
        return  info.reqGlEsVersion>=0x2000;
    }

//    @Override
//    protected void onPause() {
//        if (glSurfaceView!=null){
//            glSurfaceView.onPause();
//        }
//        super.onPause();
//    }
//
//    @Override
//    protected void onResume() {
//        if (glSurfaceView!=null){
//            glSurfaceView.onResume();
//        }
//        super.onResume();
//    }
}
